<?php
    require_once('database.php');

    // Get all categories
    $query = 'SELECT * FROM categories
              ORDER BY categoryID';
    $categories = $db->query($query);

?>
<!DOCTYPE html>
<html>

<!-- the head section -->
<head>
    <title>My Guitar Shop</title>
    <link rel="stylesheet" type="text/css" href="main.css" />
</head>

<!-- the body section -->
<body>
    <div id="page">

    <div id="header">
        <h1>Product Manager</h1>
    </div>

    <div id="main">

    <h1>Category List</h1>
    <table>
        <tr>
            <th>Name</th>
			<th>Number of Products</th>
            <!--<th>&nbsp;</th>-->
        </tr>
		<?php foreach ($categories as $category): ?>
		<tr>
			<td><?php echo $category['categoryName'] ;?></td>
			<td><?php $category_id = $category['categoryID'];
				$query = "SELECT * FROM products WHERE categoryID = $category_id ORDER BY productID";
				$products=$db->query($query);
				echo $products->rowCount();?></td>
		</tr>
		<?php endforeach; ?>
    <!-- add code for the rest of the table here -->
    
    </table>
    <br />

    <h2>Add Category</h2>
    
    <!-- add code for the form here -->
    
    <br />
    <p><a href="index.php">List Products</a></p>

    </div> <!-- end main -->

    <div id="footer">
        <p>
            &copy; <?php echo date("Y"); ?> My Guitar Shop, Inc.
        </p>
    </div>

    </div><!-- end page -->
</body>
</html>